package com.h2cloud.JUCTest.cas;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

@Slf4j(topic = "c.Test40")
public class AtomicReferenceFieldUpdaterTest {

	public static void main(String[] args) {
		Student stu = new Student();

		AtomicReferenceFieldUpdater updater =
				AtomicReferenceFieldUpdater.newUpdater(Student.class, String.class, "name");

		System.out.println(updater.compareAndSet(stu, null, "张三"));
		System.out.println(stu);
	}
}

class Student {
	volatile String name;

	@Override
	public String toString() {
		return "Student{" +
				"name='" + name + '\'' +
				'}';
	}
}
